/**
 * Author: Dmitry Ustimov
 * Date: 6/1/13
 * Time: 10:08 PM
 */

package com.gmail.dmitryustimov.ms.java7.chain_of_responsibility.mod.mod_one_type.demo.handlers6_requests5;

import com.gmail.dmitryustimov.ms.java7.patternslib.chain_of_responsibility.singleevent.Handler;

import java.math.BigDecimal;

public class CocreteHandler6<T extends Request> extends Handler<T> {

    private String name;
    protected int level;
    private BigDecimal sum = BigDecimal.valueOf(0);

    public CocreteHandler6(String name, int level) {
        this.level = level;
        this.name = name;
    }

    @Override
    public void doAction(Request request) {
        if (request instanceof Request1) {
            doAction((Request1)request);
        }
        if (request instanceof Request2) {
            doAction((Request2)request);
        }
        if (request instanceof Request3) {
            doAction((Request3)request);
        }
        if (request instanceof Request4) {
            doAction((Request4)request);
        }
        if (request instanceof Request5) {
            doAction((Request5)request);
        }
    }

    public void doAction(Request1 request) {
        sum.add(BigDecimal.valueOf(1));
    }
    public void doAction(Request2 request) {
        sum.add(BigDecimal.valueOf(2));
    }
    public void doAction(Request3 request) {
        sum.add(BigDecimal.valueOf(3));
    }
    public void doAction(Request4 request) {
        sum.add(BigDecimal.valueOf(4));
    }
    public void doAction(Request5 request) {
        sum.add(BigDecimal.valueOf(5));
    }

    @Override
    public Boolean canHandle(Request request) {
        return request.getRequestLevel() <= level;
    }
}
